/*     */ package dm.jdbc.dbaccess.ssl;
/*     */ 
/*     */ import dm.jdbc.dbaccess.DBError;
/*     */ import dm.jdbc.dbaccess.DbPureAccess;
/*     */ import java.io.IOException;
/*     */ import java.lang.reflect.Constructor;
/*     */ import java.net.Socket;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Properties;
/*     */ import javax.net.ssl.SSLSocket;
/*     */ import javax.net.ssl.SSLSocketFactory;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class MakeSSLSocket
/*     */ {
/*  36 */   private volatile boolean handshakeCompleted = false;
/*     */   
/*     */ 
/*     */ 
/*     */   public void convert(DbPureAccess dbPureAccess, Properties prop, boolean useSSLSocket)
/*     */     throws IOException, SQLException
/*     */   {
/*  43 */     SSLSocketFactory factory = null;
/*     */     try
/*     */     {
/*  46 */       Class factoryClass = 
/*  47 */         Class.forName("dm.jdbc.dbaccess.ssl.FullDuplexValidatingFactory");
/*  48 */       Constructor ctor = factoryClass
/*  49 */         .getConstructor(new Class[] { Properties.class });
/*  50 */       factory = (SSLSocketFactory)ctor
/*  51 */         .newInstance(new Properties[] { prop });
/*     */     } catch (Exception e) {
/*  53 */       DBError.throwSQLException(20002);
/*     */     }
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  60 */     SSLSocket newConnection = (SSLSocket)factory.createSocket(
/*  61 */       dbPureAccess.getSocket(), dbPureAccess.getHostName(), 
/*  62 */       dbPureAccess.getPortNumber(), true);
/*  63 */     newConnection.setSoTimeout(dbPureAccess.getSocket().getSoTimeout());
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  68 */     String[] enableProtocols = { "TLSv1" };
/*  69 */     newConnection.setEnabledProtocols(enableProtocols);
/*  70 */     newConnection
/*  71 */       .addHandshakeCompletedListener(new SSLHandshakeCompletedListener(
/*  72 */       this));
/*     */     try
/*     */     {
/*  75 */       newConnection.startHandshake();
/*     */     } catch (IOException io) {
/*  77 */       io.printStackTrace();
/*     */     }
/*     */     
/*  80 */     sharkehand(dbPureAccess, newConnection, useSSLSocket);
/*     */   }
/*     */   
/*     */   private void sharkehand(DbPureAccess dbPureAccess, SSLSocket ssl, boolean useSSLSocket) throws IOException, SQLException
/*     */   {
/*  85 */     long timeIsOver = System.currentTimeMillis() + 5000L;
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*  91 */     while ((!this.handshakeCompleted) && (
/*  92 */       timeIsOver - System.currentTimeMillis() > 0L)) {}
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*  97 */     if (useSSLSocket) {
/*  98 */       if (this.handshakeCompleted)
/*     */       {
/* 100 */         dbPureAccess.changeSocket(ssl);
/*     */       } else {
/* 102 */         DBError.throwSQLException(6064);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public void setHandshakeCompleted(boolean completed) {
/* 108 */     this.handshakeCompleted = completed;
/*     */   }
/*     */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\jdbc\dbaccess\ssl\MakeSSLSocket.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */